package com.fang.concurrency.chapter6;

/*
 * 打断 
 */
public class ThreadInterupt {

	private static final Object MONITOR = new Object();

	public static void main(String[] args) throws InterruptedException {
		/*
		 * Thread t = new Thread() {
		 * 
		 * @Override public void run() { while (true) { synchronized (MONITOR) { try {
		 * System.out.println("come in"); MONITOR.wait(10); } catch
		 * (InterruptedException e) { e.printStackTrace(); } } } } };
		 * 
		 * t.start(); Thread.sleep(100); System.out.println(t.interrupted());
		 * t.interrupt(); System.out.println(t.interrupted());
		 */
		Thread t = new Thread() {
			@Override
			public void run() {
				while (true) {

				}
			}
		};

		t.start();
		Thread main = Thread.currentThread();
		
		Thread t2 = new Thread() {
			@Override
			public void run() {
				while (true) {
					try {
						Thread.sleep(100);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					//t打断之后，t.join不会异常。因为打断的不是main线程
					main.interrupt();
					System.out.println("interrupt");
				}
			}
		};
		
		t2.start();
		try {
			//join得失main线程
			t.join();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
